package com.resto.scm.web.service.impl;

import cn.restoplus.common.utils.DateUtil;
import cn.restoplus.rpc.server.RpcService;
import com.resto.scm.web.dto.MdBillDo;
import com.resto.scm.web.manager.MdBillManager;
import com.resto.scm.web.model.MdBill;
import com.resto.scm.web.service.MdBillService;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@RpcService
public class MdBillServiceImpl implements MdBillService {

    @Resource
    private MdBillManager mdBillManager;


    public List<MdBill> selectList() {
        return mdBillManager.findMdBillsByMdBill(new MdBill());
    }


    public MdBill selectById(Long id) {
        return mdBillManager.getById(id);
    }

    /**
     * 审核成功的时候,插入账单
     *
     * @param mdBill
     * @return
     */
    @Override
    public Integer insert(MdBill mdBill) {
    //        DocStkInPlanHeader docStkInPlanHeader = docStkInPlanHeaderManager.getById(mdBill.getStockPlanId());
    //        if (docStkInPlanHeader == null){
    //            LogBetter.instance(logger)
    //                    .setLevel(LogLevel.ERROR)
    //                    .setMsg("[SCM-审核]")
    //                    .addParm("库存id:", mdBill.getStockPlanId())
    //                    .log();
    //            return 0;
    //        }
    //        //todo 账单金额的计算
    //        mdBill.setBillNumber(UniqueCodeGenerator.generate(KeyPrefix.BILL.getPrefix(), "B"));
    //        mdBill.setShopDetailId(docStkInPlanHeader.getShopDetailId());
    //        mdBill.setStockPlanId(docStkInPlanHeader.getId());
    //        mdBill.setStockPlanName(docStkInPlanHeader.getOrderName());
    //        mdBill.setStockPlanNumber(docStkInPlanHeader.getOrderCode());
    //        mdBill.setSupplierId(docStkInPlanHeader.getSupplierId());
    //        mdBill.setGmtCreate(new Date());
        return mdBillManager.insert(mdBill);
    }


    public Integer update(MdBill mdBill) {
        return mdBillManager.update(mdBill);

    }

    public Integer deleteById(Long id) {
        return mdBillManager.deleteById(id);

    }

    public List<MdBillDo> queryJoin4Page(String shopId, String beginDate, String endDate) {
        return mdBillManager.queryJoin4Page(shopId, beginDate, endDate);
    }


}
